package com.iblog.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.iblog.bean.Message;
import com.iblog.service.IMsgService;

@Controller
public class MessageController {
	Logger logger = Logger.getLogger(MessageController.class);
	@Autowired 
	private IMsgService msgService;
	
	@RequestMapping(value="insertMsg",method=RequestMethod.POST)
	public ModelAndView insertMsg(HttpServletRequest request){
		logger.debug("insertMsg");
		String username = request.getParameter("username").trim();
		String email = request.getParameter("email").trim();
		String context = request.getParameter("context").trim();
		Message message = new Message();
		message.setUsername(username);
		message.setContext(context);
		message.setEmail(email);
		
		msgService.insert(message);
		
		logger.debug("username--" + username);
		logger.debug("email--" + email);
		logger.debug("context--" + context);
		ModelAndView mav = new ModelAndView("msgDetail");
		return mav;
	}
}
